Skip to content

Conversation

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Nov 7, 2025

Additional details

When cy.wrap() is called with objects containing circular references, the logging code in stringifyActual causes infinite recursion because it doesn't track visited objects. This can lead to stack overflow errors - which cause the Cypress App to completely hang.

I'm not sure if this is an issue with other command logs, but this addresses the issue with logging in general, so it would resolve situations there as well.

Steps to test

  • Run yarn cypress:open
  • Run the example below to ensure it doesn't hang:
class Node {
  parent;
  children = [];

  appendChild(child) {
    child.parent = this;
    this.children.push(child);
    return child;
  }
}

describe("Reproduce the Cypress's issue", () => {
  it("Wrap an object containing circular references", () => {
    const rootNode = new Node();
    rootNode.appendChild(new Node()).appendChild(new Node());
    cy.wrap(rootNode);
    cy.visit("https://example.cypress.io/");
  })
})

How has the user experience changed?

Before

!!!! Complete Cypress App hang when running the test

After

Screenshot 2025-11-07 at 4 43 06 PM

PR Tasks


Note

Track visited objects to safely stringify circular structures, preventing cy.wrap() hangs and updating tests and changelog accordingly.

  • Driver utils:
    • Update packages/driver/src/cypress/utils.ts to detect circular references using a WeakSet in stringifyActual()/stringifyActualObj() and return [Circular], Array[N], or Object{N} safely.
  • Tests:
    • Add circular reference scenarios for cy.wrap() in packages/driver/cypress/e2e/commands/misc.cy.js (objects, arrays, nested/multiple refs; ensure logs include [Circular] and chaining works).
    • Expand packages/driver/cypress/e2e/cypress/utils.cy.js to assert safe stringification of circular objects/arrays and adjust expectations for small/large arrays and object key counts.
  • Changelog:
    • Note bugfix for cy.wrap() freezing on circular references in cli/CHANGELOG.md.

Written by Cursor Bugbot for commit f84e3f4. This will update automatically on new commits. Configure here.

@jennifer-shehane jennifer-shehane self-assigned this Nov 7, 2025
@cypress
Copy link

cypress bot commented Nov 7, 2025

cypress    Run #67248

Run Properties:  status check passed Passed #67248  •  git commit f84e3f438a: Merge branch 'develop' into fix-wrap-circular-reference-log
Project cypress
Branch Review fix-wrap-circular-reference-log
Run status status check passed Passed #67248
Run duration 34m 31s
Commit git commit f84e3f438a: Merge branch 'develop' into fix-wrap-circular-reference-log
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 11
Tests that did not run due to a developer annotating a test with .skip  Pending 1098
Tests that did not run due to a failure in a mocha hook  Skipped 4
Tests that passed  Passing 26594
View all changes introduced in this branch ↗︎

Warning

Partial Report: The results for the Application Quality reports may be incomplete.

UI Coverage  45.48%
  Untested elements 188  
  Tested elements 161  
Accessibility  97.98%
  Failed rules  4 critical   8 serious   2 moderate   2 minor
  Failed elements 101  

@jennifer-shehane jennifer-shehane merged commit 46d96c0 into develop Nov 11, 2025
90 of 92 checks passed
@jennifer-shehane jennifer-shehane deleted the fix-wrap-circular-reference-log branch November 11, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cypress hangs when wrapping an object containing circular references.

3 participants